#include "JsonHelper.h"
#include "WallpaperModel.h"


#include "json/json.h"
#include <QList>

QList<WallpaperModel *> JsonHelper::Deserialize(QString json)
{
    qDebug()<<"Json Deserialize Start";
    Json::Reader reader;
    Json::Value root;

    QList<WallpaperModel *> papers;
    if(reader.parse(json.toUtf8().constData(),root))
    {
        for(int i =0;i<root["images"].size();++i)
        {
            WallpaperModel* paper = new WallpaperModel();
            Json::Value image = root["images"][i];

            paper->Url = QString::fromStdString(image["url"].asString());
            paper->CopyRight = QString::fromUtf8(image["copyright"].asString().c_str());
            paper->CopyRightLink = QString::fromStdString(image["copyrightlink"].asString());
            paper->Hash = QString::fromStdString(image["hsh"].asString());

            papers.push_back(paper);
        }
    }
    qDebug()<<"Json Deserizlize end,papers.size :"<<papers.size();
    return papers;
}

QString JsonHelper::Serialize(vector<WallpaperModel> t)
{

}